import {JsonController,Controller, Render, Get, UseBefore, Session,Req,Res,Ctx,QueryParams,UseInterceptor,Post,Body,UploadedFiles,} from "routing-controllers";
import { config } from "../../config";
import { utils } from "../../utils/utils";
import { Service, Inject } from "typedi";
import {HomeServiceImpl} from '../../service/impl/HomeServiceImpl'
import TokenLoginMiddlewares from '../../middleware/TokenLoginMiddlewares';
import { JsonResponseInterceptor } from "../../middleware/JsonResponseMiddlewares";
import { UpdateEntity } from "../../entity/UpdateEntity";

@Service()
@JsonController(`${config.apiurl}/v1/public`)
@UseInterceptor(JsonResponseInterceptor)
@UseBefore(TokenLoginMiddlewares)
export class PublicControllerApi {

  static _userType:string|object;


    @Inject()
    private HomeServiceImpl!:HomeServiceImpl;


    @Post("/upLoadFile")
    public async upLoadFile (@Res() response: any,@Req() request:any, @Session() session:any,@UploadedFiles('files',{options:utils.fileUploadOptions}) files:any[]): Promise<any> {


       return files.map((e)=>{return {img_url:e.filename}}) ;
    }

    @Get("/updateApp")
    public async updateApp (@Res() response: any,@Req() request:any, @Session() session:any): Promise<any> {

        let updateData:UpdateEntity =  await this.HomeServiceImpl.updateApp(1);
        updateData.updateMsg = JSON.parse(updateData.updateMsg);
        return updateData;
      
    }

   

    
  }

  